package com.nineclock.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.utils.CurrentUserHolder;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.mapper.SysCompanyMapper;
import com.nineclock.system.mapper.SysCompanyUserMapper;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyUserService;
import io.jsonwebtoken.lang.Collections;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysCompanyUserServiceImpl extends ServiceImpl<SysCompanyUserMapper, SysCompanyUser> implements SysCompanyUserService {


    /**
     * 查询组织所有有效员工
     * @return
     */
    @Override
    public  List<SysCompanyUser> queryMembers() {
        //当前登录用户的公司中的有效员工
        Long companyId = CurrentUserHolder.get().getCompanyId();

        //

        List<SysCompanyUser> sysCompanyUserList = this.list(Wrappers.lambdaQuery(SysCompanyUser.class)
                .eq(SysCompanyUser::getCompanyId, companyId)
                .eq(SysCompanyUser::getEnable, 1));

        if (Collections.isEmpty(sysCompanyUserList)){
            throw new NcException(ResponseEnum.USER_NOT_FOUND);
        }
        return sysCompanyUserList;
    }
}
